{% macro menu_category(menu, request) %}
{% if menu.is_visible(request) and menu.is_accessible(request) %}
<li class="nav-item dropdown">
  <a class="nav-link dropdown-toggle {% if menu.is_active(request) %}active{% endif %}" data-bs-toggle="dropdown"
    href="#">
    <span class="nav-link-icon d-md-none d-lg-inline-block">
      {% if menu.icon %}<i class="{{ menu.icon }}"></i>{% endif %}
    </span>
    <span class="nav-link-title">{{ menu.display_name }}</span>
  </a>
  <div class="dropdown-menu show">
    <div class="dropdown-menu-columns">
      <div class="dropdown-menu-column">
        {% for sub_menu in menu.children %}
        {% if sub_menu.is_visible(request) and sub_menu.is_accessible(request) %}
        <a class="nav-link ps-lg-3 {% if sub_menu.is_active(request) %}active{% endif %}"
          href="{{ sub_menu.url(request) }}">
          <span class="nav-link-icon d-md-none d-lg-inline-block">
            {% if sub_menu.icon %}<i class="{{ sub_menu.icon }}"></i>{% endif %}
          </span>
          <span class="nav-link-title">{{ sub_menu.display_name }}</span>
        </a>
        {% endif %}
        {% endfor %}
      </div>
    </div>
  </div>
</li>
{% endif %}
{% endmacro %}

{% macro menu_item(menu, request) %}
{% if menu.is_visible(request) and menu.is_accessible(request) %}
<li class="nav-item">
  <a class="nav-link {% if menu.is_active(request) %}active{% endif %}" href="{{ menu.url(request) }}">
    <span class="nav-link-icon d-md-none d-lg-inline-block">
      {% if menu.icon %}<i class="{{ menu.icon }}"></i>{% endif %}
    </span>
    <span class="nav-link-title">{{ menu.display_name }}</span>
  </a>
</li>
{% endif %}
{% endmacro %}

{% macro display_menu(menu, request) %}
<div class="navbar-nav">
  {% for item in menu.items %}
  {% if item.type_ == "View" %}
  {{ menu_item(item, request) }}
  {% elif item.type_ == "Category" %}
  {{ menu_category(item, request) }}
  {% endif %}
  {% endfor %}
</div>
{% endmacro %}

{% macro render_field(field, kwargs={}) %}
<div class="mb-3 form-group row">
  {{ field.label(
    class_="form-label col-sm-2 col-form-label" + (' required-label' if field.flags.required else ''),
    **({'title': "This is a required field"} if field.flags.required else {})
  ) }}
  <div class="col-sm-10">
    {% if field.errors %}
    {{ field(class_="form-control is-invalid") }}
    {% else %}
    {{ field() }}
    {% endif %}
    {% for error in field.errors %}
    <div class="invalid-feedback">{{ error }}</div>
    {% endfor %}
    {% if field.description %}
    <small class="text-muted">{{ field.description }}</small>
    {% endif %}
  </div>
</div>
{% endmacro %}

{% macro render_form_fields(form, form_opts=None) %}
{% if form.hidden_tag is defined %}
{{ form.hidden_tag() }}
{% else %}
{% for f in form if f.widget.input_type == 'hidden' %}
{{ f }}
{% endfor %}
{% endif %}

{% for f in form if f.widget.input_type != 'hidden' %}
{{ render_field(f, kwargs) }}
{% endfor %}
{% endmacro %}